package com.znsd.zl.app.ocr.config;


import com.baidu.aip.ocr.AipOcr;
import com.znsd.zl.app.ocr.utils.JsonUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;


/**
 * <p>
 *     百度OCR识别自定义配置类
 * </p>
 * @ClassName SampleConfig
 * @Description
 * @Author jaypdd
 * @Date 2020/8/29 10:17
 * @Version v1.0
 */
@Slf4j
@Configuration
@Data
public class SampleConfig {

	@Resource
	private JsonUtils jsonUtil;

	@Value("${baidu.app-id}")
	private String appId;

	@Value("${baidu.api-key}")
	private String apiKey;

	@Value("${baidu.secret-key}")
	private String secretKey;

	@Value("${baidu.access-token}")
	private String accessToken;

	@Value("${baidu.id-card-url}")
	private String idCardUrl;

	/**
	 * 初始化百度ocrApi对象
	 * @return 将百度orc组件加入到容器中
	 */
	@Bean
	public AipOcr getAipOcr(){
		AipOcr aipOcr = new AipOcr(appId, apiKey, secretKey);
		aipOcr.setConnectionTimeoutInMillis(2000);
		aipOcr.setSocketTimeoutInMillis(60000);
		return new AipOcr(appId, apiKey, secretKey);
	}

}
